/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package io.bsly.modules.app.service.localmaster.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.bsly.common.utils.PageUtils;
import io.bsly.common.utils.Query;
import io.bsly.modules.app.dao.localDao.SysLogDao;
import io.bsly.modules.sys.entity.SysLogEntity;
import io.bsly.modules.app.service.localmaster.SysLogService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("sysLogService")
public class SysLogServiceImpl extends ServiceImpl<SysLogDao, SysLogEntity> implements SysLogService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String username = (String)params.get("username");
        String operation = (String)params.get("operation");
        String opDate = (String)params.get("opDate");

        IPage<SysLogEntity> page = this.page(
            new Query<SysLogEntity>().getPage(params),
            new LambdaQueryWrapper<SysLogEntity>()
                    .like(StringUtils.isNotBlank(username),SysLogEntity::getUsername, username)
                    .eq(StringUtils.isNotBlank(operation),SysLogEntity::getOperation, operation)
                    .apply(StringUtils.isNotBlank(opDate),"date_format(create_date,'%Y-%m-%d') = date_format('"+opDate+"','%Y-%m-%d')")
                .orderByDesc(SysLogEntity::getId)
        );

        return new PageUtils(page);
    }
}
